import com.atguigu.MD5;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.junit.Test;

import java.util.HashMap;

public class test1 {

    String serviceKey = "atguigu12";
    @Test
    public void a(){
        String ip = "192.168.1.1";
        HashMap<String, Object> user = new HashMap<>();
        user.put("name","jack");
        user.put("age","18");
        user.put("nickName","jackjack");
        String token = Jwts.builder()
                .setHeaderParam("type", "JWT")
                .setHeaderParam("alg", "HS256")

                .setId("1")
                .setIssuer("命令发布者")
                .setSubject("命令名")
                .setClaims(user)

                .signWith(SignatureAlgorithm.HS256, MD5.encrypt(serviceKey + ip))
                .compact();
        System.out.println(token);
    }


    @Test
    public void b(){
        String token = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFMyNTYifQ.eyJuaWNrTmFtZSI6ImphY2tqYWNrIiwibmFtZSI6ImphY2siLCJhZ2UiOiIxOCJ9.ZSQVEIE7CGs-HLUo-aUrsGtpK0zdt7b4Wg5AddK-kTw";
        String ip = "192.168.1.1";
        Jws<Claims> claimsJws = Jwts.parser().setSigningKey(MD5.encrypt(serviceKey + ip)).parseClaimsJws(token);
        System.out.println(claimsJws);
    }

    @Test
    public void c(){
        String a = "atguigu12127.0.0.1";
        String b = "atguigu12127.0.0.2";
        System.out.println(MD5.encrypt(a));
        System.out.println(MD5.encrypt(b));
    }

}
